import { createAPI } from '@/utils/request'
import moment from 'moment'


// 面试技巧
// 文章列表
export const getinterviewList = params => createAPI(`/articles`, 'get', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
//  .then(res => res.data)
 .then(res => ({

  counts:res.data.counts,
  items: res.data.items.map((d,i)=>({
    ...d,
    index: (params.page - 1) * params.pagesize + i + 1,
    state: d.state ? '已启用': '已禁用',
    createTime: moment(d.createTime).format('YYYY-MM-DD H:mm:ss'),
  }))
}))


  // 处理错误
.catch(() => {});


// 文章添加
export const addinterviewList = data => createAPI(`/articles`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});


// 文章状态(启用/禁用)
export const articlesState = data => createAPI(`/articles/${data.id}/${data.state}`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 文章修改/编辑
export const changeArticles = data => createAPI(`/articles/${data.id}`, 'put', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});



// 文章删除
export const deleteArticles = data => createAPI(`/articles/${data.id}`, 'delete', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});


// 文章详情
export const getArticlesDetail = params => createAPI(`/articles/${params.id}`, 'get', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)


  // 处理错误
.catch(() => {});
